/**
 * Created by dywu on 2015/9/24.
 */
angular.module('app.auth', [
    'ngCookies'
])
    .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
        $stateProvider
            .state('login', {
                url: "/login",
                templateUrl: login_viewurl + "/auth/login.html",
                controller: 'LoginController'
            })
        ;
    }])

    //管理员登录

    .controller('LoginController', ['$scope', '$state', '$cookieStore', 'LoginService', function ($scope, $state, $cookieStore, LoginService) {

        $scope.manage = {};
        $cookieStore.remove("manager_cookie");
        $cookieStore.remove("shopid_cookie");
        $scope.loginmanager = function (manager) {
            LoginService.login(manager, function (data) {
                $cookieStore.put("manager_cookie", data);
                if (data.sign == 0) {
                    $state.go('manager.list');
                }else{
                    alert("不是管理员！");
                    //ManagerService.getuserbyid(data.userid).$promise.then(function (data) {
                    //    if (data.length == 0) {
                    //        alert("不是管理员！");
                    //        return;
                    //    }
                    //    console.log(data);
                    //    $scope.shops = data[0];
                    //    $cookieStore.put("shopid_cookie", $scope.shops.shopid);
                    //    $state.go('manager.list');
                    //}, function () {
                    //    alert("不是管理员！");
                    //    return;
                    //})
                }


            }, function (data) {
                alert(data.data.reason);
            })
        }
    }])

;
